package com.example.mqttclient;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class WeatherParser {
    public static String parseWeatherInfo(String json) {
        Gson gson = new Gson();
        JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
        JsonObject results = jsonObject.getAsJsonArray("results").get(0).getAsJsonObject();
        JsonObject now = results.getAsJsonObject("now");
        String text = now.get("text").getAsString();
        String temperature = now.get("temperature").getAsString();
        return "当前天气：" + text + "，温度：" + temperature + "℃";
    }
}
